<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>新增邮件</title>
<script src="${ctx}/static/selectWin/userSelector.js"
	type="text/javascript"></script>
<link href="${ctx}/jeasyui-extensions/plugins/uploadify/uploadify.css"
	rel="stylesheet">
<script type="text/javascript"
	src="${ctx}/jeasyui-extensions/plugins/uploadify/jquery.uploadify.js"></script>
<script type="text/javascript"
	src="${ctx}/jeasyui-extensions/jeasyui-extensions/jquery-easyui-euploadify/jquery.euploadify.js"></script>
<link
	href="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/themes/default/css/ueditor.css"
	rel="stylesheet">
<script type="text/javascript"
	src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/ueditor.config.js"></script>
<script type="text/javascript"
	src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/ueditor.all.js"></script>
<script type="text/javascript"
	src="${ctx}/jeasyui-extensions/plugins/ueditor/ue1_4_3-utf8-net/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript"
	src="${ctx}/jeasyui-extensions/jeasyui-extensions/jquery-easyui-ueditor/jquery.ueditor.js"></script>

<script type="text/javascript">
	var joinFileId;
	$(function() {
		$("#tt").toolbar("align", "right");
		$(".selectPerson").click(function() {
			var $input = $(this).next();
			var oldValue = $input.val();
			$.easyui.showGridSelector($.extend(userSelectOpts, {
				multiple : true,
				onEnter : function(val) {
					$(val).each(function() {
						oldValue += this.trueName + ";";
					});
					$input.val(oldValue);
					$input.validatebox("validate");
				}
			}));
		});
		$("#edit").click(function() {
			$("#fm").attr("action", "${ctx}/basic/notifyInfo/update");
			$("#fm").submit();
		});
		$("#saveDraft").click(function() {
			$("#fm").attr("action", "${ctx}/basic/notifyInfo/saveDraft");
			$("#fm").submit();
		});

		$("#delFile").click(function() {
			if (!joinFileId) {
				showWarnInfo("没有附件，不能删除！");
				return false;
			}
			var oldFileId = $("#oldFileId").val();
			var receiverId = $("#receiverId").val();
			if (oldFileId) {
				$.get("${ctx}/basic/notifyInfo/delBasicFile", {
					joinFileId : oldFileId,
					receiverId : receiverId
				}, function(data) {
					if (data.success) {
						//移除附件
						$("#fujian").remove();
					}

					$.messager.show({
						title : "信息",
						width : 300,
						height : 100,
						msg : data.msg,
						icon : "info",
						position : "bottomRight"
					});
				}, "json");
			}
		});
		//删除附件
		/* $("#delFile").click(function() {
			if (!joinFileId) {
				showWarnInfo("没有附件，不能删除！");
				return false;
			}

		}); */

		$("#fileId").euploadify({
			width : 908,
			multiTemplate : 'simple',
			multi : true,
			auto : false,
			showStop : true,
			showCancel : true,
			swf : '${ctx }/static/uploadify/uploadify.swf',
			uploader : '${ctx }/basic/basicFile/upload',
			onSelect : function(file) {
				debugger;
				if (joinFileId) {
					$("#fileId").euploadify('setFormData', {
						'joinFileId' : joinFileId
					});
					$("#joinFileId").val(joinFileId);
				} else {
					$.post("${ctx}/basic/basicJoinFile/update", {
						codeName : "站内邮件"
					}, function(data) {
						joinFileId = data.obj ? data.obj.id : "";
						$("#joinFileId").val(joinFileId);
						$("#fileId").euploadify('setFormData', {
							'joinFileId' : joinFileId
						});
						//showInfoForCallBack(data);
					}, "json");
				}
			}
		});
	});
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<div class="easyui-panel" data-options="fit:true">
			<form id="fm" action="" method="post">
				<div id="tt" class="easyui-toolbar">
					<button type="button" id="edit" class="btn btn-primary">
						<span class="glyphicon glyphicon-send"></span> 发送
					</button>
					<button type="button" id="saveDraft" class="btn btn-primary">
						<span class="glyphicon glyphicon-saved"></span> 保存为草稿
					</button>
					<c:if test="${action eq 'transmit'}">
						<a id="delFile" class="easyui-linkbutton"
							data-options="plain: false, iconCls: 'icon-hamburg-busy'">删除附件</a>
					</c:if>
				</div>
				<table>
					<tr>
						<td>主题：</td>
						<td><input type="text" class="easyui-validatebox"
							name="title"
							value='<c:if test="${action eq 'reply' }">回复：</c:if><c:if test="${action eq 'transmit'}">转发：</c:if>${title}${notifyInfo.title}'
							data-options="required: true" style="width: 900px"></td>
					</tr>
					<tr>
						<td>收件人：</td>
						<td><a class="selectPerson easyui-linkbutton easyui-tooltip"
							title="选取收件人"
							data-options="plain: true, iconCls: 'icon-hamburg-customers'"></a>
							<input type="text" class="easyui-validatebox"
							value='${notifyInfo.receiversName}' name="receiversName"
							data-options="required: true" style="width: 869px"></td>
					</tr>
					<tr>
						<td>抄送人：</td>
						<td><a class="selectPerson easyui-linkbutton easyui-tooltip"
							title="选取抄送人"
							data-options="plain: true, iconCls: 'icon-hamburg-customers'"></a>
							<input type="text" class="easyui-validatebox"
							value='${notifyInfo.ccsName}' name="ccsName" style="width: 869px"></td>
					<tr>
						<td>密送人：</td>
						<td><a class="selectPerson easyui-linkbutton easyui-tooltip"
							title="选取密送人"
							data-options="plain: true, iconCls: 'icon-hamburg-customers'"></a>
							<input type="text" class="easyui-validatebox" value='${bccs}'
							name="bccsName" style="width: 869px"></td>
					</tr>
					<tr>
						<td>附件：</td>
						<td height="50px"><input id="fileId" name="fileId"
							type="text" /><input id="joinFileId" name="joinFileId"
							type="hidden" /></td>
					</tr>
					<c:if test="${action eq 'transmit'}">
						<input type="hidden" id="oldFileId" value="${joinFileId}" />
						<input type="hidden" id="receiverId"
							value="${notifyInfo.receiver.id }" />
						<table id="fujian">
							<c:forEach items="${basicFileList}" var="bfile">
								<tr>
									<td>&nbsp;</td>
									<%-- <td><input type="hidden" id="fileId" name="fileId" value="${ bfile.id}" /></td> --%>
									<td><a id="${ bfile.id}" href="#">${bfile.fileName}</a>&nbsp;&nbsp;&nbsp;<span>${bfile.fileSize}
											KB</span></td>
								</tr>
							</c:forEach>
						</table>
					</c:if>
					<tr>
						<td>正文：</td>
						<td><textarea name="content" class="easyui-ueditor"
								data-options="
                              required: true, height: 400,width:908, value: '',
                              template: 'full',
                              codeMirrorJsUrl: false, codeMirrorCssUrl: false
                              ">
	                              <c:if
									test="${action eq 'transmit' || action eq 'reply' }">
										<br />
										<br />
										<br />
										<br />
										----------原始邮件----------<br />
											<div style="background-color: #efefef; padding: 5px;">
												<b style="color: black;">发件人：</b>
													${notifyInfo.sender.trueName }
												<br />
												<b style="color: black;">发送时间：</b>
												 ${notifyInfo.sendTime }
												<br /><b style="color: black;">收件人：</b>
													 ${ notifyInfo.notifyContent.allReceiversName}
												<br /><b style="color: black;">抄送人：</b>
													 ${ notifyInfo.notifyContent.allCcName}
												<br /><b style="color: black;">主题：</b>&nbsp; ${ notifyInfo.title}
														<br />
											</div>
												<br />
									</c:if>
									${notifyInfo.notifyContent.content}
                              </textarea></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>
